﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Runtime.Serialization;

namespace SharedGenomics.Domain
{
    [Table(Name = "dbo.FileSchemaColumnValue")]
    [DataContract()]
    public class FileSchemaColumnValue
    {
        private EntityRef<FileSchemaColumn> _column;

        public FileSchemaColumnValue()
        {
            this.Initialize();
        }

        [Column(DbType = "Int NOT NULL", IsPrimaryKey = true)]
        [DataMember(Order = 1)]
        public int ColumnId { get; set; }

        [Association(Name = "FileSchemaColumn_FileSchemaColumnValue", Storage = "_column", ThisKey = "ColumnId", OtherKey = "Id", IsForeignKey = true)]
        public FileSchemaColumn Column
        {
            get { return this._column.Entity; }
            set
            {
                FileSchemaColumn previousValue = this._column.Entity;
                if (previousValue != value || !this._column.HasLoadedOrAssignedValue)
                {
                    if ((previousValue != null))
                    {
                        this._column.Entity = null;
                        previousValue.FileSchemaColumnValues.Remove(this);
                    }
                    this._column.Entity = value;
                    if (value != null)
                    {
                        value.FileSchemaColumnValues.Add(this);
                        this.ColumnId = value.Id;
                    }
                    else
                    {
                        this.ColumnId = default(int);
                    }
                }
            }
        }

        [Column(DbType = "VarChar(32) NOT NULL", CanBeNull = false, IsPrimaryKey = true)]
        [DataMember(Order = 2)]
        public string Value { get; set; }

        [Column(DbType = "VarChar(32)")]
        [DataMember(Order = 3)]
        public string Label { get; set; }

        [Column(DbType = "Bit NOT NULL")]
        [DataMember(Order = 4)]
        public bool IsMissing { get; set; }

        private void Initialize()
        {
            //OnCreated();
        }
    }
}
